package main

import (
	"github.com/micro/go-micro"
	"github.com/micro/cli"
	"global/core"
)

const (
	appName = "depth"
	defaultConfigFile = "../../config/config.toml"
)

var slug, configFile string
var ctx *core.Context

func main() {

	service := micro.NewService(
		micro.Name("go.micro.srv.depth"),
		micro.Version("latest"),
		micro.Flags(
			cli.StringFlag{
				Name: 			"slug",
				Usage: 			"The name of exchange",
			},
			cli.StringFlag{
				Name: 			"config",
				Usage: 			"Custom server config file",
			},
		),
	)

	service.Init(
		micro.Action(func(context *cli.Context) {
			slug = context.String("slug")
			configFile = context.String("config")
			if slug == "" {
				panic("Invalid slug supported.")
			}
			if configFile == "" {
				configFile = defaultConfigFile
			}
		}),
	)

	// 初始化工作
	ctx = core.NewContext()
	ctx.Bootstrap(configFile, appName).Initialize()

	depth := NewDepth(ctx, slug)
	depth.Run()

	if err := service.Run(); err != nil {
		panic(err.Error())
	}
}
